//alarm.txt - An object that explodes whenever anyone gets close to it and sends a message
// to a nearby creature. It helps a lot if that creature has the alarmmonst script.
//Cell 0 - Creature to send message to.
//Cell 1,2 - A stuff done flag. If > 0, set to 1 when it goes off.
//Cell 3 - Message to send. If left at 0, no message


beginobjectscript; // mine

variables;
short near_char;
short r1;
short went_off = 0;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	//if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
	//	if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0)
	//		end();
	//	}
	if (went_off > 0)
		end();
		
	near_char = get_nearest_party_char(3);

		
	if (near_char >= 0) {
		create_text_bubble("Ding!");
		print_str_color("The crystal emits a bright flash of light and a loud",2);
		print_str_color("  keening sound.",2);
		pc_heard_sound(163);
		if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) 
			sf(get_memory_cell(1),get_memory_cell(2),1);
		if (get_memory_cell(3) > 0)
			give_char_message(get_memory_cell(0),get_memory_cell(3));

		run_object_animation(7,0,70);
		set_state(3);
		}
break;

beginstate 3; // exploding
	if (am_i_doing_action() == FALSE) {
		went_off = 1;
		set_object_icon(ME,3);
		set_state(START_STATE);
		}
break;

beginstate UNLOCK_STATE;
	print_str("Unlock Spell: It doesn't affect the crystal.");	
break;

beginstate USE_STATE;
	print_str("Use Crystal: Using a crystal doesn't do anything.");
break;